package cn.tedu.springbootdemo.tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        //获取数据库对象
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/empdb?" +
                        "characterEncoding=utf8" +
                        "&serverTimezone=GMT%2B8&useSSL=false",
                "root", "111112");

        System.out.println("链接对象" + conn);
        //2.创建执行sql语句的对象
        Statement s = conn.createStatement();
        ResultSet rs = s.executeQuery("select name,sal,job from emp");
        while (rs.next()) {
            String name = rs.getString("name");
            double sal = rs.getDouble("sal");
            String job = rs.getString("job");
            System.out.println(name + ":" + sal + ":" + job);
        }
        s.close();
        rs.close();
        conn.close();
    }

}
